package com.yunji.base.event;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.Executors;

@Component
public class GuavaEventBus {
    private static final EventBus bus = new EventBus();
    private static final AsyncEventBus asyncEventBus = new AsyncEventBus(Executors.newSingleThreadExecutor());

    @Resource
    private NoticeListener noticeListener;

    @PostConstruct
    public void init() {
        bus.register(noticeListener);
        asyncEventBus.register(noticeListener);
    }

    public static void post(final Object event) {bus.post(event);}

}
